package com.itcat.api;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.api.mysql.UmsMenuApi;
import com.itcat.mapper.UmsMenuMapper;
import com.itcat.mysql.pojo.UmsMenu;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * [一句话描述该类的功能]
 *
 * @author : [Cr Mr]
 * @version : [v1.0]
 * @date : [2022/4/1 22:55]
 */
@DubboService
public class UmsMenuApiImpl implements UmsMenuApi {

    @Autowired
    private UmsMenuMapper umsMenuMapper;

    /***
     * 根据roleId查询Menu对象集合
     * @author Cr Mr
     * @date 2022/4/1 23:01
     */
    @Override
    public List<UmsMenu> getMenuList(List<Long> ids) {
        if (CollUtil.isEmpty(ids)) {
            return null;
        }
        return umsMenuMapper.selectMenuList(ids);
    }

    /***
     * 查询所有Menu对象集合
     * @author Cr Mr
     * @date 2022/4/1 23:01
     */
    @Override
    public List<UmsMenu> getMenuAll() {
        List<UmsMenu> umsMenus = umsMenuMapper.selectList(new LambdaQueryWrapper<UmsMenu>().eq(UmsMenu::getHidden, 0L));
        return umsMenus;
    }

    /***
     * 分页查询后台菜单
     * @author Cr Mr
     * @date 2022/4/3 16:16
     */
    @Override
    public Page<UmsMenu> selectPage(Long parentId, Integer pageNum, Integer pageSize) {
        Page<UmsMenu> menuPage = new Page<>();
        LambdaQueryWrapper<UmsMenu> lqw = new LambdaQueryWrapper<>();
        lqw.eq(parentId != null, UmsMenu::getParentId, parentId);
        Page<UmsMenu> selectPage = umsMenuMapper.selectPage(menuPage, lqw);
        return selectPage;
    }

    /***
     * 添加后台菜单
     * @author Cr Mr
     * @date 2022/4/3 16:30
     */
    @Override
    public void create(UmsMenu umsMenu) {
        umsMenuMapper.insert(umsMenu);
    }

    /***
     * 根据ID删除后台菜单
     * @author Cr Mr
     * @date 2022/4/3 16:36
     */
    @Override
    public void delete(Long id) {
        umsMenuMapper.deleteById(id);
        umsMenuMapper.deleteMenu(id);
    }

    @Override
    public void update(Long id, UmsMenu umsMenu) {
        umsMenuMapper.update(umsMenu, new LambdaQueryWrapper<UmsMenu>().eq(id != null,
                UmsMenu::getId, id));
    }

    /***
     * 修改菜单显示状态
     * @author Cr Mr
     * @date 2022/4/3 17:08
     */
    @Override
    public void updateHidden(Long id, Integer hidden) {
        umsMenuMapper.update(null, new LambdaUpdateWrapper<UmsMenu>().eq(id != null, UmsMenu::getId, id).
                set(UmsMenu::getHidden, hidden));
    }

    /***
     * 修改菜单显示状态
     * @author Cr Mr
     * @date 2022/4/3 17:14
     */
    @Override
    public UmsMenu getUmsMenu(Long id) {
        umsMenuMapper.selectById(id);
        return null;
    }


}
